﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Common;
using Northwind.Domain;

namespace Ex04
{
    class Program
    {
        static void Main(string[] args)
        {
            var db = new NorthwindEntities();
            FilterSortProducts(db.Products).Dump("This query executes on SQL Server");

            Product[] localProducts =
            {
                new Product { ID = 1, Description = "Local Product Test", LastSale = new DateTime (2007, 2, 3) }
            };

            FilterSortProducts(localProducts.AsQueryable()).Dump("The same query - executing locally");
            Console.ReadKey();
        }

        static IQueryable<Product> FilterSortProducts(IQueryable<Product> input)
        {
            var dateTime = DateTime.Now.AddDays(-7);
            return
                from p in input
                where !p.Discontinued && p.LastSale < dateTime
                orderby p.Description
                select p;
        }
    }
}
